package com.frejoys.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.admin.AuthRuleAccessDeleteDto;
import com.frejoys.common.dto.admin.UserNameAndPhoneDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.admin.AuthRuleAccessListVo;
import com.frejoys.service.AuthGroupAccessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户权限组关联表", description = "用户权限组关联表")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixAdmin)
@Authorization(Authority.Private)
public class AdminAuthGroupAccessController {

    private final AuthGroupAccessService authGroupAccessService;

    @Operation(summary = "管理员权限列表")
    @PostMapping("/auth/rule/access/list")
    public Result<IPage<AuthRuleAccessListVo>> authRuleAccessList(@RequestBody @Validated UserNameAndPhoneDto dto) {
        return Result.success(authGroupAccessService.authRuleAccessList(dto));
    }

    @Operation(summary = "删除管理员权限")
    @PostMapping("/auth/rule/access/delete")
    public Result deleteAuthRuleAccess(@RequestBody @Validated AuthRuleAccessDeleteDto dto) {
        return Result.success(authGroupAccessService.authRuleAccessUpInfo(dto));
    }
}
